package com.example.myapplication.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;


import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import com.example.myapplication.R;
import com.example.myapplication.bean.Communication;

/**
 * CommunicationAdapter类是一个适配器类，用于将Communication对象绑定到RecyclerView的Item视图上。
 * 继承自BaseQuickAdapter类，泛型参数为Communication和BaseViewHolder。
 */
public class CommunicationAdapter extends BaseQuickAdapter<Communication, BaseViewHolder> {
       private Context context;
       private  ICommunicationListener listener;
       public CommunicationAdapter(Context context,ICommunicationListener listener){


            super(R.layout.item_communicition);
        this.context = context;
        this.listener = listener;
}
    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, Communication communication) {
baseViewHolder.setText(R.id.tv_title,communication.getTitle());
      if(!TextUtils.isEmpty(communication.getImage_url())){
          baseViewHolder.getView(R.id.img_url).setVisibility(View.VISIBLE);
          Glide.with(context).load(communication.getImage_url()).into((ImageView) baseViewHolder.getView(R.id.img_url));
        }
          baseViewHolder.setText(R.id.tv_time,communication.getTime());
        baseViewHolder.getView(R.id.card_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 如果监听器不为空，则调用监听器的onCommunicationClick方法，并传入通信对象
                if (listener != null) {
                    listener.onCommunicationClick(communication);
                }
            }
        });
    }
}
